//
//  CLIntroduceViewController.m
//  chanlin
//
//  Created by shuhui on 15-5-19.
//  Copyright (c) 2015年 chanlin. All rights reserved.
//

#import "CLIntroduceViewController.h"
#import "AppDelegate.h"
#import "CLGloble.h"

@interface CLIntroduceViewController ()
@property (nonatomic,strong) UIScrollView *scrollView;

@end

@implementation CLIntroduceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.frame=CGRectMake(0, 0, GlobleWidth,GlobleHeight);
    
    UIImageView *info=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, GlobleWidth, GlobleHeight)];
    info.userInteractionEnabled=YES;
    
    
    info.image=[UIImage imageNamed:@"uh3.png"];
    [self.view addSubview:info];
    
    UITapGestureRecognizer *tap1=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapColose2:)];
    [info addGestureRecognizer:tap1];

    
    self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    self.scrollView.contentSize=CGSizeMake(GlobleWidth*4, GlobleHeight);
    self.scrollView.backgroundColor=[UIColor whiteColor];
    self.scrollView.pagingEnabled=YES;
    self.scrollView.showsHorizontalScrollIndicator=NO;
    self.scrollView.showsVerticalScrollIndicator=NO;
    [self.view addSubview:self.scrollView];
    
    NSMutableArray *colorArr = [[NSMutableArray alloc]init];
    [colorArr addObject:[UIColor redColor]];
    [colorArr addObject:[UIColor yellowColor]];
    [colorArr addObject:[UIColor orangeColor]];
    [colorArr addObject:[UIColor greenColor]];
    
    for(int i=0;i<4;i++){
        UIImageView *imageview=[[UIImageView alloc] initWithFrame:CGRectMake(GlobleWidth*i, 0, GlobleWidth, GlobleHeight)];
        imageview.image=[UIImage imageNamed:[NSString stringWithFormat:@"uh2-%d.jpg",i]];
        imageview.backgroundColor = [colorArr objectAtIndex:i];
        [self.scrollView addSubview:imageview];
        
        if(i==3){
            
//            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 80)];
//            label.backgroundColor = [UIColor whiteColor];
//            label.center = CGPointMake(GlobleWidth/2, GlobleHeight/2+180);
//            label.text = @"GO";
//            label.textAlignment = NSTextAlignmentCenter;
//            label.font = [UIFont systemFontOfSize:20.f];
//            [imageview addSubview:label];
            
            UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapColose:)];
            [imageview addGestureRecognizer:tap];
            imageview.userInteractionEnabled=YES;
        }
    }
}

- (void)tapColose:(UITapGestureRecognizer *)recognizer{
    CGPoint p=[recognizer locationInView:self.view];
    CGRect buttonRect=(GlobleHeight)>480?CGRectMake(100.f, 468, 120, 32):
    CGRectMake(55.f, GlobleHeight-125, 210, 45);
    if(!CGRectContainsPoint(buttonRect, p)){
        return;
    }
    [UIView animateWithDuration:0.2
                     animations:^(){
                         self.scrollView.alpha=0;
                         
                     }
                     completion:^(BOOL finish){
                         [self.scrollView removeFromSuperview];
//                         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//                         [defaults setBool:YES forKey:[NSString stringWithFormat:@"%@%@",KeyOfUserHelpShow,[[CLGloble sharedInstance] appVersion]]];
//                         [(AppDelegate *)[UIApplication sharedApplication].delegate nilIntroduceVC];
                         
    }];
}


- (void)tapColose2:(UITapGestureRecognizer *)recognizer{
    CGPoint p=[recognizer locationInView:self.view];
    CGRect buttonRect=(GlobleHeight)>480?CGRectMake(110.f, 500, 145, 90):
    CGRectMake(55.f, GlobleHeight-125, 210, 45);
    if(!CGRectContainsPoint(buttonRect, p)){
        return;
    }
    [UIView animateWithDuration:0.2
                     animations:^(){
                         self.view.alpha=0;
                         
                     }
                     completion:^(BOOL finish){
                         [self.view removeFromSuperview];
                         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
                         [defaults setBool:YES forKey:[NSString stringWithFormat:@"%@%@",KeyOfUserHelpShow,[[CLGloble sharedInstance] appVersion]]];
                         [(AppDelegate *)[UIApplication sharedApplication].delegate nilIntroduceVC];
                         
                     }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
